# Maintainer: kpcyrd <kpcyrd[at]archlinux[dot]org>

pkgname=psalm
pkgver=5.16.0
pkgrel=1
_commit=2897ba636551a8cb61601cc26f6ccfbba6c36591
pkgdesc='A static analysis tool for finding errors in PHP applications'
url="https://psalm.dev/"
arch=('any')
license=('MIT')
depends=('php')
makedepends=('composer' 'git')
#source=("${pkgname}-${pkgver}.tar.gz::https://github.com/vimeo/psalm/archive/refs/tags/${pkgver}.tar.gz"
source=("git+https://github.com/vimeo/psalm.git#commit=${_commit}"
        "composer.lock")
b2sums=('SKIP'
        '60bffe1f941cd347d2a744ece5c7d80c5e46dcf555f84296040e88859cd658c03cfef81e1c9f8132343af981175b8e36c0135625cbb90537a75afc3d84ab8c36')

prepare() {
  cd ${pkgname}
  cp ../composer.lock .
  composer install
  composer bin box install
  php bin/improve_class_alias.php
  php -r 'require "vendor/autoload.php"; Psalm\Internal\VersionUtils::dump();'
}

updlockfiles() {
  cd ${pkgname}
  rm -f composer.lock
  composer update --no-install
  cp composer.lock "${outdir}/"
}

build() {
  cd ${pkgname}
  vendor/bin/box compile
}

check() {
  rm -rf testing/
  mkdir -p testing/src
  cd testing/

  composer init -n --name test/test
  composer install
  ../${pkgname}/build/psalm.phar --init
  ../${pkgname}/build/psalm.phar

  cat > src/index.php <<EOF
<?php echo(phpversion());
EOF
  ../${pkgname}/build/psalm.phar

  cat > src/index.php <<EOF
<?php echo(this_is_invalid_to_provoke_an_error());
EOF
  if ../${pkgname}/build/psalm.phar; then
    echo 'did not detect invalid php as invalid'
    exit 1
  fi
}

package() {
  cd ${pkgname}
  install -Dm 755 ./build/psalm.phar "${pkgdir}/usr/bin/psalm"
}

# vim: ts=2 sw=2 et:
